package org.jeecg.modules.checdw.controller;

import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.util.*;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import javassist.runtime.Desc;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.util.DateUtils;
import org.jeecg.common.util.RedisUtil;
import org.jeecg.modules.checdw.entity.AgChecdw;
import org.jeecg.modules.checdw.entity.Cheljwd;
import org.jeecg.modules.checdw.entity.DetaCheCDWRecord;
import org.jeecg.modules.checdw.mapper.AgChecdwMapper;
import org.jeecg.modules.checdw.service.IAgChecdwService;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;

import org.jeecg.modules.cheldygx.entity.AgCheldygx;
import org.jeecg.modules.cheldygx.service.IAgCheldygxService;
import org.jeecg.modules.kaoqtj.entity.AgKaoqtj;
import org.jeecg.modules.shextdj.entity.DetaShextData;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.modules.tongxjl.entity.AgTongxjl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.servlet.ModelAndView;
import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.aspect.annotation.AutoLog;

import static java.lang.StrictMath.*;

/**
 * @Description: 车场定位
 * @Author: jeecg-boot
 * @Date: 2020-09-25
 * @Version: V1.0
 */
@Api(tags = "车场定位")
@RestController
@RequestMapping("/checdw/agChecdw")
@Slf4j
public class AgChecdwController extends JeecgController<AgChecdw, IAgChecdwService> {
    @Autowired
    private IAgChecdwService agChecdwService;

    @Autowired
    AgChecdwMapper agChecdwMapper;

    @Autowired
    private RedisUtil redisUtil;

    @Autowired
    private IAgCheldygxService agCheldygxService;

    @GetMapping(value = "/quchong")
    public Result<?> quChong() {

//        Map <String, List <AgChecdw>> list = agChecdwService.list().parallelStream()
//                                                .collect(Collectors.groupingBy(AgChecdw::getCheph));



        return  Result.ok("");
    }



    @GetMapping(value = "/carPosList")
    public Result<?> carPosList() {
 //       IPage<AgChecdw> pageList = new Page<AgChecdw>(1, 999);
//
//        List<AgChecdw> list = agChecdwMapper.carPosList();
//        pageList.setRecords(list);


        IPage<Object> pageList=new Page<Object>(1, 999);
        pageList.setRecords((List) redisUtil.get("carPosList"));

        log.info("redis车场carPosList:"+pageList);
        return Result.ok(pageList);
    }

    /**
     * 分页列表查询
     *
     * @param agChecdw
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    @AutoLog(value = "车场定位-分页列表查询")
    @ApiOperation(value = "车场定位-分页列表查询", notes = "车场定位-分页列表查询")
    @GetMapping(value = "/list")
    public Result<?> queryPageList(AgChecdw agChecdw,
                                   @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                   @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                   HttpServletRequest req) {
        QueryWrapper<AgChecdw> queryWrapper = QueryGenerator.initQueryWrapper(agChecdw, req.getParameterMap());
        Page<AgChecdw> page = new Page<AgChecdw>(pageNo, pageSize);
        IPage<AgChecdw> pageList = agChecdwService.page(page, queryWrapper);

        return Result.ok(pageList);
    }

    /**
     * 添加
     *
     * @param agChecdw
     * @return
     */
    @AutoLog(value = "车场定位-添加")
    @ApiOperation(value = "车场定位-添加", notes = "车场定位-添加")
    @PostMapping(value = "/add")
    public Result<?> add(@RequestBody AgChecdw agChecdw) {
        agChecdwService.save(agChecdw);
        return Result.ok("添加成功！");
    }

    /**
     * 编辑
     *
     * @param agChecdw
     * @return
     */
    @AutoLog(value = "车场定位-编辑")
    @ApiOperation(value = "车场定位-编辑", notes = "车场定位-编辑")
    @PutMapping(value = "/edit")
    public Result<?> edit(@RequestBody AgChecdw agChecdw) {
        agChecdwService.updateById(agChecdw);
        return Result.ok("编辑成功!");
    }

    /**
     * 通过id删除
     *
     * @param id
     * @return
     */
    @AutoLog(value = "车场定位-通过id删除")
    @ApiOperation(value = "车场定位-通过id删除", notes = "车场定位-通过id删除")
    @DeleteMapping(value = "/delete")
    public Result<?> delete(@RequestParam(name = "id", required = true) String id) {
        agChecdwService.removeById(id);
        return Result.ok("删除成功!");
    }

    /**
     * 批量删除
     *
     * @param ids
     * @return
     */
    @AutoLog(value = "车场定位-批量删除")
    @ApiOperation(value = "车场定位-批量删除", notes = "车场定位-批量删除")
    @DeleteMapping(value = "/deleteBatch")
    public Result<?> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
        this.agChecdwService.removeByIds(Arrays.asList(ids.split(",")));
        return Result.ok("批量删除成功!");
    }

    /**
     * 通过id查询
     *
     * @param id
     * @return
     */
    @AutoLog(value = "车场定位-通过id查询")
    @ApiOperation(value = "车场定位-通过id查询", notes = "车场定位-通过id查询")
    @GetMapping(value = "/queryById")
    public Result<?> queryById(@RequestParam(name = "id", required = true) String id) {
        AgChecdw agChecdw = agChecdwService.getById(id);
        if (agChecdw == null) {
            return Result.error("未找到对应数据");
        }
        return Result.ok(agChecdw);
    }

    /**
     * 导出excel
     *
     * @param request
     * @param agChecdw
     */
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, AgChecdw agChecdw) {
        return super.exportXls(request, agChecdw, AgChecdw.class, "车场定位");
    }

    /**
     * 通过excel导入数据
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
        return super.importExcel(request, response, AgChecdw.class);
    }

}
